package com.haiwen.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 韩要雷
 *
 * cookie的创建：
 *  创建：new Cookie(k,v)
 *  创建cookie必须通过response对象进行响应到浏览器才能看到这个cookie
 *  响应：response.addCookie(k)
 */
@WebServlet("/cookie01")
public class cookie01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.创建cookie
        Cookie cookie = new Cookie("userName","刘德华");

        //2.响应给浏览器
        resp.addCookie(cookie);


        Cookie cookie01 = new Cookie("userPwd","1234");
        resp.addCookie(cookie01);
    }
}
